//
//  MSInviteViewModel.m
//  MSMain
//
//  Created by Dgh Hv on 2018/9/19.
//  Copyright © 2018年 土豆. All rights reserved.
//

#import "MSInviteViewModel.h"
#import "MSRewardOrInviteListModel.h"
#import "MSAnchorWorkModel.h"

@implementation MSInviteViewModel

-(void)getAnchorInviteInfoComplete:(void(^)(NSString * Reward,NSString *SubordinateCount))complete
{
    [[[XLHTTPSessionManager sharedManager]XLV2GET:@"api/v2/user/GetInviteCount" parameters:@{@"userId":[[XLAccountManager shareInstance]model].Id} resultClass:nil] subscribeNext:^(id x) {
        NSLog(@"%@",x);
        NSString * Reward = @"";
        NSString * SubordinateCount = @"";
        NSDictionary * dict = (NSDictionary *)x;
        if(ValidDict(dict))
        {
            Reward = NSStringFormat(@"%@",dict[@"Reward"]);
            SubordinateCount = NSStringFormat(@"%@",dict[@"SubordinateCount"]);
        }
        if(complete)
        {
            complete(Reward,SubordinateCount);
        }
    } error:^(NSError *error) {
        NSLog(@"%@", error);
        if(complete)
        {
            complete(@"",@"");
        }
    }];
}

-(void)getAnchorInviteContentComplete:(void(^)(NSString * Content,NSString *InviteUrl,NSString *Title))complete
{
    [[[XLHTTPSessionManager sharedManager]XLV2GET:@"api/v2/user/GetInviteUrl" parameters:@{@"userId":[[XLAccountManager shareInstance]model].Id} resultClass:nil] subscribeNext:^(id x) {
        NSLog(@"%@",x);
        NSString * Content = @"";
        NSString * InviteUrl = @"";
        NSString * Title = @"";
        NSDictionary * dict = (NSDictionary *)x;
        if(ValidDict(dict))
        {
            Content = NSStringFormat(@"%@",dict[@"Content"]);
            InviteUrl = NSStringFormat(@"%@",dict[@"InviteUrl"]);
            Title = NSStringFormat(@"%@",dict[@"Title"]);
        }
        if(complete)
        {
            complete(Content,InviteUrl,Title);
        }
    } error:^(NSError *error) {
        NSLog(@"%@", error);
        if(complete)
        {
            complete(@"",@"",@"");
        }
    }];
}

-(void)getInviteRewardListParams:(NSDictionary *)params Complete:(void(^)(NSArray * data))complete
{
    NSMutableDictionary * dict = [[NSMutableDictionary alloc]initWithDictionary:params];
    [dict setObject:[[XLAccountManager shareInstance]model].Id forKey:@"userId"];
    [[[XLHTTPSessionManager sharedManager]XLV2GET:@"api/v2/user/GetInviteRewardList" parameters:dict resultClass:[MSRewardOrInviteListModel class]] subscribeNext:^(id x) {
        NSLog(@"%@",x);
        NSArray * data = (NSArray *)x;
        if(ValidArray(data))
        {
            if(complete)
            {
                complete(data);
            }
        }else
        {
            if(complete)
            {
                complete(@[]);
            }
        }
        
    } error:^(NSError *error) {
        NSLog(@"%@", error);
        if(complete)
        {
            complete(@[]);
        }
    }];
}


-(void)getInviteListParams:(NSDictionary *)params Complete:(void(^)(NSArray * data))complete
{
    NSMutableDictionary * dict = [[NSMutableDictionary alloc]initWithDictionary:params];
    [dict setObject:[[XLAccountManager shareInstance]model].Id forKey:@"userId"];
    [[[XLHTTPSessionManager sharedManager]XLV2GET:@"api/v2/user/GetSubordinateList" parameters:dict resultClass:[MSRewardOrInviteListModel class]] subscribeNext:^(id x) {
        NSLog(@"%@",x);
        NSArray * data = (NSArray *)x;
        if(ValidArray(data))
        {
            if(complete)
            {
                complete(data);
            }
        }else
        {
            if(complete)
            {
                complete(@[]);
            }
        }
        
    } error:^(NSError *error) {
        NSLog(@"%@", error);
        if(complete)
        {
            complete(@[]);
        }
    }];
}

-(void)getAnchorWordComplete:(void(^)(MSAnchorWorkModel * model))complete
{
    [[[XLHTTPSessionManager sharedManager]XLV2GET:@"Api/v2/AnchorDest/GetAnchorDeskInfo" parameters:@{@"userId":[[XLAccountManager shareInstance]model].Id} resultClass:[MSAnchorWorkModel class]] subscribeNext:^(id x) {
        MSAnchorWorkModel * model = (MSAnchorWorkModel *)x;
        if(complete)
        {
            complete(model);
        }

    } error:^(NSError *error) {
        NSLog(@"%@", error);
        if(complete)
        {
            complete(nil);
        }
    }];
}
                                                                  


@end
